﻿<cftry>

<cfset callback = url.callback />
<cfset page     = url.page />
<cfset start    = url.start />
<cfset sort     = url.sort />
<cfset dir      = url.dir />
<cfset limit    = url.limit />


<cfquery name="getExitForm" datasource="IBOSE_GLOBAL">
	SELECT  *, 
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDIS IS NULL, getdate(), DATEREPLIEDIS) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDIS IS NULL, getdate(), DATEREPLIEDIS),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDIS IS NULL, getdate(), DATEREPLIEDIS),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDIS IS NULL, getdate(), DATEREPLIEDIS),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATIS,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDIS IS NULL, getdate(), DATEREPLIEDIS), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDIS IS NULL, getdate(), DATEREPLIEDIS), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDIS IS NULL, getdate(), DATEREPLIEDIS), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDIS IS NULL, getdate(), DATEREPLIEDIS), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDIS IS NULL, getdate(), DATEREPLIEDIS), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATIS,
            <!---</cfif>--->  
            <!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDDH IS NULL, getdate(), DATEREPLIEDDH) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDDH IS NULL, getdate(), DATEREPLIEDDH),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDDH IS NULL, getdate(), DATEREPLIEDDH),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDDH IS NULL, getdate(), DATEREPLIEDDH),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDDH IS NULL, getdate(), DATEREPLIEDDH), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDDH IS NULL, getdate(), DATEREPLIEDDH), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDDH IS NULL, getdate(), DATEREPLIEDDH), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDDH IS NULL, getdate(), DATEREPLIEDDH), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDDH IS NULL, getdate(), DATEREPLIEDDH), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATDH,
            <!---</cfif>--->  
            <!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDSUN IS NULL, getdate(), DATEREPLIEDSUN) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDSUN IS NULL, getdate(), DATEREPLIEDSUN),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDSUN IS NULL, getdate(), DATEREPLIEDSUN),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDSUN IS NULL, getdate(), DATEREPLIEDSUN),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDSUN IS NULL, getdate(), DATEREPLIEDSUN), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDSUN IS NULL, getdate(), DATEREPLIEDSUN), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDSUN IS NULL, getdate(), DATEREPLIEDSUN), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDSUN IS NULL, getdate(), DATEREPLIEDSUN), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDSUN IS NULL, getdate(), DATEREPLIEDSUN), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATSUN,
            <!---</cfif>--->  
            <!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDGLOBE IS NULL, getdate(), DATEREPLIEDGLOBE) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDGLOBE IS NULL, getdate(), DATEREPLIEDGLOBE),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDGLOBE IS NULL, getdate(), DATEREPLIEDGLOBE),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDGLOBE IS NULL, getdate(), DATEREPLIEDGLOBE),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDGLOBE IS NULL, getdate(), DATEREPLIEDGLOBE), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDGLOBE IS NULL, getdate(), DATEREPLIEDGLOBE), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDGLOBE IS NULL, getdate(), DATEREPLIEDGLOBE), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDGLOBE IS NULL, getdate(), DATEREPLIEDGLOBE), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDGLOBE IS NULL, getdate(), DATEREPLIEDGLOBE), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATGLOBE,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDBT IS NULL, getdate(), DATEREPLIEDBT) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDBT IS NULL, getdate(), DATEREPLIEDBT),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDBT IS NULL, getdate(), DATEREPLIEDBT),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDBT IS NULL, getdate(), DATEREPLIEDBT),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDBT IS NULL, getdate(), DATEREPLIEDBT), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDBT IS NULL, getdate(), DATEREPLIEDBT), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDBT IS NULL, getdate(), DATEREPLIEDBT), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDBT IS NULL, getdate(), DATEREPLIEDBT), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDBT IS NULL, getdate(), DATEREPLIEDBT), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATBT,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDIAL IS NULL, getdate(), DATEREPLIEDIAL) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDIAL IS NULL, getdate(), DATEREPLIEDIAL),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDIAL IS NULL, getdate(), DATEREPLIEDIAL),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDIAL IS NULL, getdate(), DATEREPLIEDIAL),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDIAL IS NULL, getdate(), DATEREPLIEDIAL), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDIAL IS NULL, getdate(), DATEREPLIEDIAL), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDIAL IS NULL, getdate(), DATEREPLIEDIAL), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDIAL IS NULL, getdate(), DATEREPLIEDIAL), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDIAL IS NULL, getdate(), DATEREPLIEDIAL), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATIAL,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDIAW IS NULL, getdate(), DATEREPLIEDIAW) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDIAW IS NULL, getdate(), DATEREPLIEDIAW),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDIAW IS NULL, getdate(), DATEREPLIEDIAW),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDIAW IS NULL, getdate(), DATEREPLIEDIAW),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDIAW IS NULL, getdate(), DATEREPLIEDIAW), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDIAW IS NULL, getdate(), DATEREPLIEDIAW), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDIAW IS NULL, getdate(), DATEREPLIEDIAW), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDIAW IS NULL, getdate(), DATEREPLIEDIAW), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDIAW IS NULL, getdate(), DATEREPLIEDIAW), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATIAW,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDIT IS NULL, getdate(), DATEREPLIEDIT) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDIT IS NULL, getdate(), DATEREPLIEDIT),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDIT IS NULL, getdate(), DATEREPLIEDIT),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDIT IS NULL, getdate(), DATEREPLIEDIT),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDIT IS NULL, getdate(), DATEREPLIEDIT), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDIT IS NULL, getdate(), DATEREPLIEDIT), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDIT IS NULL, getdate(), DATEREPLIEDIT), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDIT IS NULL, getdate(), DATEREPLIEDIT), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDIT IS NULL, getdate(), DATEREPLIEDIT), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATIT,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDACCT IS NULL, getdate(), DATEREPLIEDACCT) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDACCT IS NULL, getdate(), DATEREPLIEDACCT),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDACCT IS NULL, getdate(), DATEREPLIEDACCT),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDACCT IS NULL, getdate(), DATEREPLIEDACCT),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDACCT IS NULL, getdate(), DATEREPLIEDACCT), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDACCT IS NULL, getdate(), DATEREPLIEDACCT), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDACCT IS NULL, getdate(), DATEREPLIEDACCT), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDACCT IS NULL, getdate(), DATEREPLIEDACCT), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDACCT IS NULL, getdate(), DATEREPLIEDACCT), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATACCT,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDASSET IS NULL, getdate(), DATEREPLIEDASSET) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDASSET IS NULL, getdate(), DATEREPLIEDASSET),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDASSET IS NULL, getdate(), DATEREPLIEDASSET),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDASSET IS NULL, getdate(), DATEREPLIEDASSET),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDASSET IS NULL, getdate(), DATEREPLIEDASSET), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDASSET IS NULL, getdate(), DATEREPLIEDASSET), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDASSET IS NULL, getdate(), DATEREPLIEDASSET), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDASSET IS NULL, getdate(), DATEREPLIEDASSET), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDASSET IS NULL, getdate(), DATEREPLIEDASSET), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATASSET,
            <!---</cfif>---> 
            <!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDTR IS NULL, getdate(), DATEREPLIEDTR) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDTR IS NULL, getdate(), DATEREPLIEDTR),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDTR IS NULL, getdate(), DATEREPLIEDTR),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDTR IS NULL, getdate(), DATEREPLIEDTR),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDTR IS NULL, getdate(), DATEREPLIEDTR), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDTR IS NULL, getdate(), DATEREPLIEDTR), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDTR IS NULL, getdate(), DATEREPLIEDTR), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDTR IS NULL, getdate(), DATEREPLIEDTR), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDTR IS NULL, getdate(), DATEREPLIEDTR), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATTR,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDTTK IS NULL, getdate(), DATEREPLIEDTTK) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDTTK IS NULL, getdate(), DATEREPLIEDTTK),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDTTK IS NULL, getdate(), DATEREPLIEDTTK),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDTTK IS NULL, getdate(), DATEREPLIEDTTK),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDTTK IS NULL, getdate(), DATEREPLIEDTTK), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDTTK IS NULL, getdate(), DATEREPLIEDTTK), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDTTK IS NULL, getdate(), DATEREPLIEDTTK), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDTTK IS NULL, getdate(), DATEREPLIEDTTK), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDTTK IS NULL, getdate(), DATEREPLIEDTTK), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATTTK,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDTTM IS NULL, getdate(), DATEREPLIEDTTM) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDTTM IS NULL, getdate(), DATEREPLIEDTTM),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDTTM IS NULL, getdate(), DATEREPLIEDTTM),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDTTM IS NULL, getdate(), DATEREPLIEDTTM),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDTTM IS NULL, getdate(), DATEREPLIEDTTM), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDTTM IS NULL, getdate(), DATEREPLIEDTTM), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDTTM IS NULL, getdate(), DATEREPLIEDTTM), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDTTM IS NULL, getdate(), DATEREPLIEDTTM), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDTTM IS NULL, getdate(), DATEREPLIEDTTM), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATTTM,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDTTT IS NULL, getdate(), DATEREPLIEDTTT) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDTTT IS NULL, getdate(), DATEREPLIEDTTT),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDTTT IS NULL, getdate(), DATEREPLIEDTTT),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDTTT IS NULL, getdate(), DATEREPLIEDTTT),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDTTT IS NULL, getdate(), DATEREPLIEDTTT), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDTTT IS NULL, getdate(), DATEREPLIEDTTT), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDTTT IS NULL, getdate(), DATEREPLIEDTTT), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDTTT IS NULL, getdate(), DATEREPLIEDTTT), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDTTT IS NULL, getdate(), DATEREPLIEDTTT), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATTTT,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDRSC IS NULL, getdate(), DATEREPLIEDRSC) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDRSC IS NULL, getdate(), DATEREPLIEDRSC),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDRSC IS NULL, getdate(), DATEREPLIEDRSC),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDRSC IS NULL, getdate(), DATEREPLIEDRSC),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDRSC IS NULL, getdate(), DATEREPLIEDRSC), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDRSC IS NULL, getdate(), DATEREPLIEDRSC), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDRSC IS NULL, getdate(), DATEREPLIEDRSC), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDRSC IS NULL, getdate(), DATEREPLIEDRSC), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDRSC IS NULL, getdate(), DATEREPLIEDRSC), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATRSC,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEREPLIEDWC IS NULL, getdate(), DATEREPLIEDWC) , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  IF(DATEREPLIEDWC IS NULL, getdate(), DATEREPLIEDWC),  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEREPLIEDWC IS NULL, getdate(), DATEREPLIEDWC),  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  IF(DATEREPLIEDWC IS NULL, getdate(), DATEREPLIEDWC),  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEREPLIEDWC IS NULL, getdate(), DATEREPLIEDWC), DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, IIF(DATEREPLIEDWC IS NULL, getdate(), DATEREPLIEDWC), DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEREPLIEDWC IS NULL, getdate(), DATEREPLIEDWC), DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, IIF(DATEREPLIEDWC IS NULL, getdate(), DATEREPLIEDWC), DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, IIF(DATEREPLIEDWC IS NULL, getdate(), DATEREPLIEDWC), DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATWC,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  DATEREPLIEDA , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  DATEREPLIEDA,  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  DATEREPLIEDA,  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  DATEREPLIEDA,  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, DATEREPLIEDA, DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, DATEREPLIEDA, DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, DATEREPLIEDA, DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, DATEREPLIEDA, DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, DATEREPLIEDA, DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATA,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  DATEREPLIEDB , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  DATEREPLIEDB,  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  DATEREPLIEDB,  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  DATEREPLIEDB,  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, DATEREPLIEDB, DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, DATEREPLIEDB, DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, DATEREPLIEDB, DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, DATEREPLIEDB, DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, DATEREPLIEDB, DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATB,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  DATEREPLIEDC , DATEEMAILTOCLR) /7 ) *5) +
                CASE dayofweek( DATEEMAILTOCLR )
                WHEN 1 THEN mod(datediff( day,  DATEREPLIEDC,  DATEEMAILTOCLR ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  DATEREPLIEDC,  DATEEMAILTOCLR ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEEMAILTOCLR ), mod(datediff( day,  DATEREPLIEDC,  DATEEMAILTOCLR ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, DATEREPLIEDC, DATEEMAILTOCLR ) /7 ) *5) +
                CASE DATEPART(dw, DATEEMAILTOCLR)
                WHEN 1 THEN (datediff( day, DATEREPLIEDC, DATEEMAILTOCLR ) % 7) - 2
                WHEN 7 THEN (datediff( day, DATEREPLIEDC, DATEEMAILTOCLR ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEEMAILTOCLR )) < (datediff( day, DATEREPLIEDC, DATEEMAILTOCLR ) % 7) 
                    then (7-DATEPART( dw, DATEEMAILTOCLR )) 
                    else (datediff( day, DATEREPLIEDC, DATEEMAILTOCLR ) % 7) 
                    end
                END )
                AS TATC,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEENDORSEDTP IS NULL, getdate(), DATEENDORSEDTP) , DATEACCOMPLISHED) /7 ) *5) +
                CASE dayofweek( DATEACCOMPLISHED )
                WHEN 1 THEN mod(datediff( day,  IF(DATEENDORSEDTP IS NULL, getdate(), DATEENDORSEDTP),  DATEACCOMPLISHED ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEENDORSEDTP IS NULL, getdate(), DATEENDORSEDTP),  DATEACCOMPLISHED ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEACCOMPLISHED ), mod(datediff( day,  IF(DATEENDORSEDTP IS NULL, getdate(), DATEENDORSEDTP),  DATEACCOMPLISHED ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEENDORSEDTP IS NULL, getdate(), DATEENDORSEDTP), DATEACCOMPLISHED ) /7 ) *5) +
                CASE DATEPART(dw, DATEACCOMPLISHED)
                WHEN 1 THEN (datediff( day, IIF(DATEENDORSEDTP IS NULL, getdate(), DATEENDORSEDTP), DATEACCOMPLISHED ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEENDORSEDTP IS NULL, getdate(), DATEENDORSEDTP), DATEACCOMPLISHED ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEACCOMPLISHED )) < (datediff( day, IIF(DATEENDORSEDTP IS NULL, getdate(), DATEENDORSEDTP), DATEACCOMPLISHED ) % 7) 
                    then (7-DATEPART( dw, DATEACCOMPLISHED )) 
                    else (datediff( day, IIF(DATEENDORSEDTP IS NULL, getdate(), DATEENDORSEDTP), DATEACCOMPLISHED ) % 7) 
                    end
                END )
                AS POSTEMPTAT,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEFORWARDTPINIT IS NULL, getdate(), DATEFORWARDTPINIT) , DATEACCOMPLISHED) /7 ) *5) +
                CASE dayofweek( DATEACCOMPLISHED )
                WHEN 1 THEN mod(datediff( day,  IF(DATEFORWARDTPINIT IS NULL, getdate(), DATEFORWARDTPINIT),  DATEACCOMPLISHED ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEFORWARDTPINIT IS NULL, getdate(), DATEFORWARDTPINIT),  DATEACCOMPLISHED ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEACCOMPLISHED ), mod(datediff( day,  IF(DATEFORWARDTPINIT IS NULL, getdate(), DATEFORWARDTPINIT),  DATEACCOMPLISHED ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEFORWARDTPINIT IS NULL, getdate(), DATEFORWARDTPINIT), DATEACCOMPLISHED ) /7 ) *5) +
                CASE DATEPART(dw, DATEACCOMPLISHED)
                WHEN 1 THEN (datediff( day, IIF(DATEFORWARDTPINIT IS NULL, getdate(), DATEFORWARDTPINIT), DATEACCOMPLISHED ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEFORWARDTPINIT IS NULL, getdate(), DATEFORWARDTPINIT), DATEACCOMPLISHED ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEACCOMPLISHED )) < (datediff( day, IIF(DATEFORWARDTPINIT IS NULL, getdate(), DATEFORWARDTPINIT), DATEACCOMPLISHED ) % 7) 
                    then (7-DATEPART( dw, DATEACCOMPLISHED )) 
                    else (datediff( day, IIF(DATEFORWARDTPINIT IS NULL, getdate(), DATEFORWARDTPINIT), DATEACCOMPLISHED ) % 7) 
                    end
                END )
                AS TATTPINT,
            <!---</cfif>--->
			<!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEFORWARDTA IS NULL, getdate(), DATEFORWARDTA) , DATEACCOMPLISHED) /7 ) *5) +
                CASE dayofweek( DATEACCOMPLISHED )
                WHEN 1 THEN mod(datediff( day,  IF(DATEFORWARDTA IS NULL, getdate(), DATEFORWARDTA),  DATEACCOMPLISHED ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEFORWARDTA IS NULL, getdate(), DATEFORWARDTA),  DATEACCOMPLISHED ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEACCOMPLISHED ), mod(datediff( day,  IF(DATEFORWARDTA IS NULL, getdate(), DATEFORWARDTA),  DATEACCOMPLISHED ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEFORWARDTA IS NULL, getdate(), DATEFORWARDTA), DATEACCOMPLISHED ) /7 ) *5) +
                CASE DATEPART(dw, DATEACCOMPLISHED)
                WHEN 1 THEN (datediff( day, IIF(DATEFORWARDTA IS NULL, getdate(), DATEFORWARDTA), DATEACCOMPLISHED ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEFORWARDTA IS NULL, getdate(), DATEFORWARDTA), DATEACCOMPLISHED ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEACCOMPLISHED )) < (datediff( day, IIF(DATEFORWARDTA IS NULL, getdate(), DATEFORWARDTA), DATEACCOMPLISHED ) % 7) 
                    then (7-DATEPART( dw, DATEACCOMPLISHED )) 
                    else (datediff( day, IIF(DATEFORWARDTA IS NULL, getdate(), DATEFORWARDTA), DATEACCOMPLISHED ) % 7) 
                    end
                END )
                AS TATTA,
            <!---</cfif>--->	
            <!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEFORWARDTPE IS NULL, getdate(), DATEFORWARDTPE) , DATEACCOMPLISHED) /7 ) *5) +
                CASE dayofweek( DATEACCOMPLISHED )
                WHEN 1 THEN mod(datediff( day,  IF(DATEFORWARDTPE IS NULL, getdate(), DATEFORWARDTPE),  DATEACCOMPLISHED ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEFORWARDTPE IS NULL, getdate(), DATEFORWARDTPE),  DATEACCOMPLISHED ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEACCOMPLISHED ), mod(datediff( day,  IF(DATEFORWARDTPE IS NULL, getdate(), DATEFORWARDTPE),  DATEACCOMPLISHED ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEFORWARDTPE IS NULL, getdate(), DATEFORWARDTPE), DATEACCOMPLISHED ) /7 ) *5) +
                CASE DATEPART(dw, DATEACCOMPLISHED)
                WHEN 1 THEN (datediff( day, IIF(DATEFORWARDTPE IS NULL, getdate(), DATEFORWARDTPE), DATEACCOMPLISHED ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEFORWARDTPE IS NULL, getdate(), DATEFORWARDTPE), DATEACCOMPLISHED ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEACCOMPLISHED )) < (datediff( day, IIF(DATEFORWARDTPE IS NULL, getdate(), DATEFORWARDTPE), DATEACCOMPLISHED ) % 7) 
                    then (7-DATEPART( dw, DATEACCOMPLISHED )) 
                    else (datediff( day, IIF(DATEFORWARDTPE IS NULL, getdate(), DATEFORWARDTPE), DATEACCOMPLISHED ) % 7) 
                    end
                END )
                AS TATPE,
            <!---</cfif>--->	
            <!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
                Abs((floor( datediff( day,  IF(DATEAVAILOCATM IS NULL, getdate(), DATEAVAILOCATM) , DATEACCOMPLISHED) /7 ) *5) +
                CASE dayofweek( DATEACCOMPLISHED )
                WHEN 1 THEN mod(datediff( day,  IF(DATEAVAILOCATM IS NULL, getdate(), DATEAVAILOCATM),  DATEACCOMPLISHED ) , 7) - 2
                WHEN 7 THEN mod(datediff( day,  IF(DATEAVAILOCATM IS NULL, getdate(), DATEAVAILOCATM),  DATEACCOMPLISHED ) , 7) - 1
                ELSE
                LEAST(7-dayofweek(  DATEACCOMPLISHED ), mod(datediff( day,  IF(DATEAVAILOCATM IS NULL, getdate(), DATEAVAILOCATM),  DATEACCOMPLISHED ) , 7))
                END) AS
                TATDH,
            <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>---> 
                Abs((floor( datediff( day, IIF(DATEAVAILOCATM IS NULL, getdate(), DATEAVAILOCATM), DATEACCOMPLISHED ) /7 ) *5) +
                CASE DATEPART(dw, DATEACCOMPLISHED)
                WHEN 1 THEN (datediff( day, IIF(DATEAVAILOCATM IS NULL, getdate(), DATEAVAILOCATM), DATEACCOMPLISHED ) % 7) - 2
                WHEN 7 THEN (datediff( day, IIF(DATEAVAILOCATM IS NULL, getdate(), DATEAVAILOCATM), DATEACCOMPLISHED ) % 7) - 1
                ELSE
                    case 
                    when (7-DATEPART( dw, DATEACCOMPLISHED )) < (datediff( day, IIF(DATEAVAILOCATM IS NULL, getdate(), DATEAVAILOCATM), DATEACCOMPLISHED ) % 7) 
                    then (7-DATEPART( dw, DATEACCOMPLISHED )) 
                    else (datediff( day, IIF(DATEAVAILOCATM IS NULL, getdate(), DATEAVAILOCATM), DATEACCOMPLISHED ) % 7) 
                    end
                END )
                AS TATATM  
            <!---</cfif>--->			
				
				

	   FROM EGINCLRMAIN
	   
	   <cfset where             = "()" >
	   
     <cfif isdefined('url.query')>
	   WHERE LASTNAME LIKE '%#url.query#%'
	 <cfelse>
	 	 <cfset where             = " (" >
            <cfset tmpdatafield      = "" >
            <cfset tmpfilteroperator = "0" >
			
        	<cfloop index="counter" from="0" to="100">
            
            	
            
            	<cftry>
					<cfset filterdatafield = trim(url['filter[#counter#][field]'])>
					<cfcatch>
						<cfbreak>
					</cfcatch>
				</cftry>
            
            	
            
            	<cfset filterdatafield = url['filter[#counter#][field]']>
				
            	<cfset filtervalue     = url['filter[#counter#][data][value]']>
				
				<cfset filtertype      = url['filter[#counter#][data][type]']>
				
				
                <cfif tmpdatafield EQ "" >
                
                	<cfset tmpdatafield = filterdatafield >	
                    	
				<cfelseif tmpdatafield NEQ filterdatafield >
                
				    <cfset where = "#where# ) AND ( " >
                    
				<cfelseif tmpdatafield EQ filterdatafield >
                
					<cfif tmpfilteroperator EQ 0>
                    	<cfset where = "#where# AND " >
                    <cfelse>
                    	<cfset where = "#where# OR " >
                    </cfif>
					
                </cfif>
                
                <cfif ucase(filtertype) EQ "STRING" >
					<cfset where = "#where##filterdatafield#  LIKE '%#filtervalue#%'" >
				<cfelseif  ucase(filtertype) EQ "NUMERIC" >
					<cfset filtercondition = url['filter[#counter#][data][comparison]']>
					<cfset expression = "#Ucase(Trim(filtercondition))#" >
               
	               		<cfif expression  EQ "LT">
						   	<cfset where = "#where##filterdatafield#  < #filtervalue#">
						<cfelseif expression EQ "GT"> 	   
							<cfset where = "#where##filterdatafield#  > #filtervalue#">
						<cfelseif expression EQ "EQ"> 	   	
							<cfset where = "#where##filterdatafield#  = #filtervalue#">
						<cfelse>
					
					</cfif>
				<cfelseif  ucase(filtertype) EQ "DATE" >
					<cfset filtercondition = url['filter[#counter#][data][comparison]']>
					<cfset expression = "#Ucase(Trim(filtercondition))#" >
					
						
	                    <cfset filtervalue = CreateODBCDateTime(filtervalue) />
               
	               		<cfif expression  EQ "LT">
	               			<cfset where = "#where##filterdatafield#  < #filtervalue#">
						<cfelseif expression EQ "GT"> 	   
							<cfset where = "#where##filterdatafield#  > #filtervalue#">
						<cfelseif expression EQ "EQ"> 	   	
							<cfset where = "#where##filterdatafield#  = #filtervalue#">
						<cfelse>
							<cfset where = "#where##filterdatafield#  = #filtervalue#">
					    </cfif>
				<cfelse>
					<!---boolean--->
					<cfif filtervalue EQ 'true' >
						<cfset filtervalue = 'Yes' >
					<cfelse>
						<cfset filtervalue = 'No' >
					</cfif>
					<cfset where = "#where##filterdatafield#  LIKE '%#filtervalue#%'" >
				</cfif>
                
                <cfset tmpdatafield      = filterdatafield >
		
            </cfloop>
            
            <cfset where = "#where#)" >
			<cfset where = Replace(where, "''", "'" , "all") />
			
			<cfif trim(where) NEQ "()">
				WHERE <cfoutput>#PreserveSingleQuotes(where)#</cfoutput>
			<cfelse>
			</cfif>
			
     </cfif>
	ORDER BY #sort# #dir#
    OFFSET #start# ROWS
         FETCH NEXT #limit# ROWS ONLY
	
    <!---<cfif Ucase(client.DBMS) EQ 'MYSQL'>
     	LIMIT #start#, #limit#
    <cfelseif Ucase(client.DBMS) EQ 'MSSQL'>
         OFFSET #start# ROWS
         FETCH NEXT #limit# ROWS ONLY
    <cfelse>
    	LIMIT #start#, #limit#
    </cfif>--->
	  ;
	       
	
</cfquery>

  
<cfquery name="countTotal" datasource="IBOSE_GLOBAL">
	 SELECT  COUNT(*) AS TOTALREC
	   FROM EGINCLRMAIN
      
     <cfif isdefined('url.query')>
	   WHERE LASTNAME LIKE '%#url.query#%'
	 <cfelse>
	    <cfif trim(where) NEQ "()">
			WHERE <cfoutput>#PreserveSingleQuotes(where)#</cfoutput>
		<cfelse>
		</cfif>
     </cfif>
	
	  ;
</cfquery>

<cfset cnt = 0 >

<cfoutput>
	
	#callback#(
	{
    "totalCount":"#countTotal.TOTALREC#",
	"topics":[
	
		<cfloop query="getExitForm">
			
		{
			"ID":         #SerializeJSON(ID)#,
			"DATERECEIVEDRL":               #SerializeJSON(DATERECEIVEDRL)#,
			"DATEACCOMPLISHED":  #SerializeJSON(DATEACCOMPLISHED)#,
			"PERSONNELIDNO":        #SerializeJSON(PERSONNELIDNO)#,
			"LASTNAME":                      #SerializeJSON(LASTNAME)#, 
			"FIRSTNAME":                      #SerializeJSON(FIRSTNAME)#, 
			"GUID":                      #SerializeJSON(GUID)#, 
			"PERSONNELIDNO":                      #SerializeJSON(PERSONNELIDNO)#, 
			"MIDDLENAME":                      #SerializeJSON(MIDDLENAME)#, 
			"EXT":                      #SerializeJSON(EXT)#, 
			"POSITIONTITLE":                      #SerializeJSON(POSITIONTITLE)#,
			"LEVEL":                      #SerializeJSON(LEVEL)#,
			"COMPANY":                      #SerializeJSON(COMPANY)#,
			"COSTCENTERCODE":                      #SerializeJSON(COSTCENTERCODE)#,
			"BRANDORGROUP":                      #SerializeJSON(BRANDORGROUP)#,
			"DIVISION":                      #SerializeJSON(DIVISION)#, 
			"DEPARTMENT":                      #SerializeJSON(DEPARTMENT)#, 
			"SECTION":                      #SerializeJSON(SECTION)#, 
			"GENDER":                      #SerializeJSON(GENDER)#, 
			"BIRTHDATE":                      #SerializeJSON(BIRTHDATE)#, 
			"AGE":                      #SerializeJSON(AGE)#, 
			"CIVILSTATUS":                      #SerializeJSON(CIVILSTATUS)#,
			"ADDRESS":                      #SerializeJSON(ADDRESS)#,
			"CONTACTNUM":                      #SerializeJSON(CONTACTNUM)#,
			"EMAILADD":                      #SerializeJSON(EMAILADD)#,
			"DATEHIRED":                      #SerializeJSON(DATEHIRED)#,
			"DATERESIGNEFFECT":                      #SerializeJSON(DATERESIGNEFFECT)#, 
			"TENUREPERYEAR":                      #SerializeJSON(TENUREPERYEAR)#, 
			"TENUREPERMONTH":                      #SerializeJSON(TENUREPERMONTH)#, 
			"EMPLOYMENTSTATUS":                      #SerializeJSON(EMPLOYMENTSTATUS)#, 
			"IMMEDSUPERIOR":                      #SerializeJSON(IMMEDSUPERIOR)#, 
			"DEPTHEAD":                      #SerializeJSON(DEPTHEAD)#, 
			"DATEEMAILTOCLR":                      #SerializeJSON(DATEEMAILTOCLR)#,
			"ISTAG":                      #SerializeJSON(ISTAG)#,
			"DATEREPLIEDIS":                      #SerializeJSON(DATEREPLIEDIS)#,
			"REMARKSIS":                      #SerializeJSON(REMARKSIS)#,
			"DETAILIS":                      #SerializeJSON(DETAILIS)#,
			"TATIS":                      #SerializeJSON(TATIS)#, 
			"DATEREPLIEDDH":                      #SerializeJSON(DATEREPLIEDDH)#, 
			"REMARKSDH":                      #SerializeJSON(REMARKSDH)#, 
			"DETAILDH":                      #SerializeJSON(DETAILDH)#, 
			"TATDH":                      #SerializeJSON(TATDH)#, 
			"DATEREPLIEDSUN":                      #SerializeJSON(DATEREPLIEDSUN)#, 
			"REMARKSSUN":                      #SerializeJSON(REMARKSSUN)#,
			"DETAILSUN":                      #SerializeJSON(DETAILSUN)#,
			"TATSUN":                      #SerializeJSON(TATSUN)#,
			"DATEREPLIEDGLOBE":                      #SerializeJSON(DATEREPLIEDGLOBE)#,
			"REMARKSGLOBE":                      #SerializeJSON(REMARKSGLOBE)#,
			"DETAILGLOBE":                      #SerializeJSON(DETAILGLOBE)#, 
			"TATGLOBE":                      #SerializeJSON(TATGLOBE)#, 
			"DATEREPLIEDBT":                      #SerializeJSON(DATEREPLIEDBT)#, 
			"REMARKSBT":                      #SerializeJSON(REMARKSBT)#, 
			"DETAILBT":                      #SerializeJSON(DETAILBT)#, 
			"TATBT":                      #SerializeJSON(TATBT)#, 
			"DATEREPLIEDIAL":                      #SerializeJSON(DATEREPLIEDIAL)#,
			"REMARKSIAL":                      #SerializeJSON(REMARKSIAL)#,
			"DETAILIAL":                      #SerializeJSON(DETAILIAL)#,
			"TATIAL":                      #SerializeJSON(TATIAL)#,
			"DATEREPLIEDIAW":                      #SerializeJSON(DATEREPLIEDIAW)#,
			"REMARKSIAW":                      #SerializeJSON(REMARKSIAW)#, 
			"DETAILIAW":                      #SerializeJSON(DETAILIAW)#, 
			"TATIAW":                      #SerializeJSON(TATIAW)#, 
			"DATEREPLIEDIT":                      #SerializeJSON(DATEREPLIEDIT)#, 
			"REMARKSIT":                      #SerializeJSON(REMARKSIT)#, 
			"DETAILIT":                      #SerializeJSON(DETAILIT)#, 
			"TATIT":                      #SerializeJSON(TATIT)#,
			"DATEREPLIEDACCT":                      #SerializeJSON(DATEREPLIEDACCT)#,
			"REMARKSACCT":                      #SerializeJSON(REMARKSACCT)#,
			"DETAILACCT":                      #SerializeJSON(DETAILACCT)#,
			"TATACCT":                      #SerializeJSON(TATACCT)#,
			"DATEREPLIEDASSET":                      #SerializeJSON(DATEREPLIEDASSET)#, 
			"REMARKSASSET":                      #SerializeJSON(REMARKSASSET)#, 
			"DETAILASSET":                      #SerializeJSON(DETAILASSET)#,
			"TATASSET":                      #SerializeJSON(TATASSET)#, 
			"DATEREPLIEDTR":                      #SerializeJSON(DATEREPLIEDTR)#, 
			"REMARKSTR":                      #SerializeJSON(REMARKSTR)#, 
			"DETAILTR":                      #SerializeJSON(DETAILTR)#, 
			"TATTR":                      #SerializeJSON(TATTR)#, 
			"DATEREPLIEDTTK":                      #SerializeJSON(DATEREPLIEDTTK)#, 
			"REMARKSTTK":                      #SerializeJSON(REMARKSTTK)#,
			"DETAILTTK":                      #SerializeJSON(DETAILTTK)#,
			"TATTTK":                      #SerializeJSON(TATTTK)#,
			"DATEREPLIEDTTM":                      #SerializeJSON(DATEREPLIEDTTM)#,
			"REMARKSTTM":                      #SerializeJSON(REMARKSTTM)#,
			"DETAILTTM":                      #SerializeJSON(DETAILTTM)#, 
			"TATTTM":                      #SerializeJSON(TATTTM)#, 
			"DATEREPLIEDTTT":                      #SerializeJSON(DATEREPLIEDTTT)#,
			"REMARKSTTT":                      #SerializeJSON(REMARKSTTT)#, 
			"DETAILTTT":                      #SerializeJSON(DETAILTTT)#, 
			"TATTTT":                      #SerializeJSON(TATTTT)#, 
			"DATEREPLIEDRSC":                      #SerializeJSON(DATEREPLIEDRSC)#, 
			"REMARKSRSC":                      #SerializeJSON(REMARKSRSC)#, 
			"DETAILRSC":                      #SerializeJSON(DETAILRSC)#, 
			"TATRSC":                      #SerializeJSON(TATRSC)#,
			"DATEREPLIEDWC":                      #SerializeJSON(DATEREPLIEDWC)#,
			"REMARKSWC":                      #SerializeJSON(REMARKSWC)#,
			"DETAILWC":                      #SerializeJSON(DETAILWC)#,
			"TATWC":                      #SerializeJSON(TATWC)#,
			"DATEREPLIEDA":                      #SerializeJSON(DATEREPLIEDA)#,
			"REMARKSA":                      #SerializeJSON(REMARKSA)#,
			"DETAILA":                      #SerializeJSON(DETAILA)#,
			"TATA":                      #SerializeJSON(TATA)#,
			"DATEREPLIEDB":                      #SerializeJSON(DATEREPLIEDB)#,
			"REMARKSB":                      #SerializeJSON(REMARKSB)#,
			"DETAILB":                      #SerializeJSON(DETAILB)#,
			"TATB":                      #SerializeJSON(TATB)#,
			"DATEREPLIEDC":                      #SerializeJSON(DATEREPLIEDC)#,
			"REMARKSC":                      #SerializeJSON(REMARKSC)#,
			"DETAILC":                      #SerializeJSON(DETAILC)#,
			"TATC":                      #SerializeJSON(TATC)#,
			"DATECLEAREDFCD":                      #SerializeJSON(DATECLEAREDFCD)#, 
			"DATEPROCCLEARANCE":                      #SerializeJSON(DATEPROCCLEARANCE)#, 
			"DATECOMPLETEDLOA":                      #SerializeJSON(DATECOMPLETEDLOA)#,
			"DATEENDORSEDTP":                      #SerializeJSON(DATEENDORSEDTP)#, 
			"POSTEMPTAT":                      #SerializeJSON(POSTEMPTAT)#, 
			"REMARKSCOD":                      #SerializeJSON(REMARKSCOD)#, 
			"CAUSEOFSEP":                      #SerializeJSON(CAUSEOFSEP)#, 
			"PROCESSEDBY":                      #SerializeJSON(PROCESSEDBY)#, 
			"DATEFORWARDTPINIT":                      #SerializeJSON(DATEFORWARDTPINIT)#, 
			"TATTPINT":                      #SerializeJSON(TATTPINT)#,
			"DATEFORWARDTA":                      #SerializeJSON(DATEFORWARDTA)#,
			"TATTA":                      #SerializeJSON(TATTA)#,
			"DATEFORWARDTPE":                      #SerializeJSON(DATEFORWARDTPE)#,
			"TATPE":                      #SerializeJSON(TATPE)#,
			"TERMINALPAYRESULT":                      #SerializeJSON(TERMINALPAYRESULT)#, 
			"DATEFORWARDTR":                      #SerializeJSON(DATEFORWARDTR)#, 
			"DATEAVAILOCATM":                      #SerializeJSON(DATEAVAILOCATM)#,
			"TATATM":                      #SerializeJSON(TATATM)#, 
			"TOTALNODAYSP":                      #SerializeJSON(TOTALNODAYSP)#, 
			"REMARKSFORWARD":                      #SerializeJSON(REMARKSFORWARD)#, 
			"DATERELEASECOE":                      #SerializeJSON(DATERELEASECOE)#, 
			"DATERELEASEFINALCOE":                      #SerializeJSON(DATERELEASEFINALCOE)#,
			<cfset pcount = 0 >
			<cfif len(DATEREPLIEDIS) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDDH) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDSUN) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDGLOBE) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDBT) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDIAL) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDIAW) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDIT) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDACCT) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDASSET) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDTR) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDTTK) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDTTM) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDTTT) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDRSC) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			<cfif len(DATEREPLIEDWC) GT 5 >
				<cfset pcount = pcount + 1 >
			</cfif>
			
			<cfif pcount NEQ  0 >
			  <cfset percentcount = (pcount / 16) * 100 >
			<cfelse>
			  <cfset percentcount = pcount >
			</cfif>
			
			"PROGRESS": #percentcount#
			
		}
	
		<cfif countTotal.TOTALREC NEQ cnt>
			<cfoutput>,</cfoutput>
			<cfset cnt = cnt + 1 >
	    </cfif>
		</cfloop>
	
	]  
	})
	
</cfoutput>
	<cfcatch>
		<cfoutput>
	
		#callback#(
		{
	    "totalCount":"1",
		"topics":[{
				"ID":  #SerializeJSON(cfcatch.Detail)#,
			},{
				"LASTNAME":  #SerializeJSON(cfcatch.Message & ' -  ' & where)#,
			}]
		})
		</cfoutput>
	</cfcatch>
</cftry>



<cfsetting showdebugoutput="no" >